// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++

package main

import (
	"fmt"
)

// 定义节点
type TreeNode struct {
	//数据项
	Data int
	//左子树的地址
	Left *TreeNode
	//右子树的地址
	Right *TreeNode
}

// 插入节点
func Insert(root *TreeNode) []int {
	if root == nil {
		return nil
	}

	left := Insert(root.Left)
	right := Insert(root.Right)

	output := make([]int, 0)

	output = append(output, left...)
	output = append(output, root.Data)
	output = append(output, right...)
	return output
}

func main() {
	root := TreeNode{Data: 1}
	root.Left = &TreeNode{Data: 2}
	root.Left.Left = &TreeNode{Data: 4}
	root.Right = &TreeNode{Data: 3}
	root.Right.Left = &TreeNode{Data: 5}
	root.Right.Right = &TreeNode{Data: 6}

	output := Insert(&root)
	fmt.Println(output)
}

//$ go run binaryTree.go
//[4 2 1 5 3 6]
